﻿$(function($){
	
	/**
	 * 初始化
	 */
	
	function init(){
		$("#_input span a").click(function(){
			 oInput = $("#oid").val().toString();
			if(oInput!="")
			{
				moudles(oInput);
			}
			else{
				alert("请输入运单号、手机号或收件人姓名");
			}
		});
	}
	init();
	/**
	 * 数据交互
	 */
	function moudles(){
		service.query(oInput,aMsg);
		function aMsg(data){
	
			var mailMName,mailAddr;
			var view = new views(); 
			if(data[0]!=undefined)
			{
				for(var i=0;i<mailCoo.length;i++)
				{
					if(data[2]==mailCoo[i]["mName"])
					{
						mailMName=mailCoo[i]["name"];
						mailAddr=mailCoo[i]["addr"];
					}
					
				}
					
					view.achieve(data,mailMName,mailAddr);
			}
			else
			{
				view.unAchieve();
				
			}
		}
	}
	
	/**
	 * 视图控制器
	 */
	function views(data,name,addr){
		var req = $("#res");
		req.fadeIn(300); 
		$("#rescontent").empty();
	}
	views.prototype.achieve = function(data,name,addr)
		{
			$("#rescontent").append("<p>"+data[0]+"同学，您的订单("+data[1]+")"+"已于"+data[3]+"到达"+name+"。请尽快到"+addr+"领取。");
		}
		
	views.prototype.unAchieve = function()
		{
			$("#rescontent").append("<p>对不起，您的订单尚未到达学校。</p>");
		}
	
	
	
	/**
	 * 快递设定
	 */
	
	var mailCoo = [
		               {
		            	   "name":"申通快递",
		            	   "mName":"st",
		            	   "addr":"二教负一层"
		            	   
		               },{
		            	   "name":"中通快递",
		            	   "mName":"zt",
		            	   "addr":"二号宿舍楼负一层"
		            	   
		               },{
		            	   "name":"圆通快递",
		            	   "mName":"yt",
		            	   "addr":"二号宿舍楼负一层"
		               }
	               ];
});